package api

import (
	"context"
	"gitee.com/leo-xin/novel_distribution_sdk_go/wending/kyy/config"
	"net/http"
	"net/url"
)

type UserDesktopListApiService service

type UserDesktopRequest struct {
	ctx           context.Context
	ApiService    *UserDesktopListApiService
	startTime     *uint64
	endTime       *uint64
	subProviderId *uint64
	page          *uint64
	pageSize      *uint64
}

type UserDesktopResponse struct {
	Code    *int64               `json:"code,omitempty"`
	Message *string              `json:"message,omitempty"`
	Data    *UserDesktopListData `json:"data,omitempty"`
}

type UserDesktopListData struct {
	TotalPage *uint64                `json:"totalPage,omitempty"`
	UserList  []*UserDesktopListItem `json:"userDesktopList,omitempty"`
}

type UserDesktopListItem struct {
	UserId         *uint64 `json:"userId,omitempty"`
	AddDesktopTime *uint64 `json:"addDesktopTime,omitempty"`
}

func (r *UserDesktopRequest) StartTime(startTime uint64) *UserDesktopRequest {
	r.startTime = &startTime
	return r
}

func (r *UserDesktopRequest) EndTime(endTime uint64) *UserDesktopRequest {
	r.endTime = &endTime
	return r
}

func (r *UserDesktopRequest) SubProviderId(subProviderId uint64) *UserDesktopRequest {
	r.subProviderId = &subProviderId
	return r
}

func (r *UserDesktopRequest) Page(page uint64) *UserDesktopRequest {
	r.page = &page
	return r
}

func (r *UserDesktopRequest) PageSize(pageSize uint64) *UserDesktopRequest {
	r.pageSize = &pageSize
	return r
}

func (r *UserDesktopRequest) Execute() (*UserDesktopResponse, *http.Response, error) {
	return r.ApiService.getExecute(r)
}

func (r *UserDesktopRequest) AppSecret(AppSecret string) *UserDesktopRequest {
	r.ctx = context.WithValue(r.ctx, config.AppSecret, AppSecret)
	return r
}

func (r *UserDesktopRequest) AppKey(AppKey string) *UserDesktopRequest {
	r.ctx = context.WithValue(r.ctx, config.AppKey, AppKey)
	return r
}

func (r *UserDesktopRequest) WithLog(enable bool) *UserDesktopRequest {
	if enable {
		r.ctx = context.WithValue(r.ctx, config.ContextEnableLog, true)
	}
	return r
}

func (a *UserDesktopListApiService) Get(ctx context.Context) *UserDesktopRequest {
	return &UserDesktopRequest{
		ApiService: a,
		ctx:        ctx,
	}
}

func (a *UserDesktopListApiService) getExecute(r *UserDesktopRequest) (*UserDesktopResponse, *http.Response, error) {

	cfg := a.client.Cfg
	var (
		localVarPath         = cfg.GetBasePath() + "/dist-api/user/desktop/list"
		localVarHTTPMethod   = http.MethodGet
		localVarPostBody     map[string]string
		localVarFormParams   = url.Values{}
		localVarHeaderParams = make(map[string]string)
		localVarQueryParams  = url.Values{}
		localVarReturnValue  *UserDesktopResponse
	)

	r.ctx = a.client.prepareCtx(r.ctx)

	if ok, GenericOpenAPIError := hasStartTimeAndEndTime(r.startTime, r.endTime); !ok {
		return localVarReturnValue, nil, GenericOpenAPIError
	}
	localVarQueryParams.Add("startTime", toString(r.startTime))
	localVarQueryParams.Add("endTime", toString(r.endTime))

	if r.subProviderId != nil {
		localVarQueryParams.Add("subProviderId", toString(r.subProviderId))
	}
	if r.page != nil {
		localVarQueryParams.Add("page", toString(r.page))
	}
	if r.pageSize != nil {
		localVarQueryParams.Add("pageSize", toString(r.pageSize))
	}

	req, err := a.client.buildRequest(r.ctx, localVarPath, localVarHTTPMethod, localVarPostBody, localVarHeaderParams, localVarQueryParams, localVarFormParams)
	if err != nil {
		return localVarReturnValue, nil, err
	}

	localVarHTTPResponse, err := a.client.call(r.ctx, req, &localVarReturnValue)
	if err != nil || localVarHTTPResponse == nil {
		return localVarReturnValue, localVarHTTPResponse, err
	}
	return localVarReturnValue, localVarHTTPResponse, nil
}
